<?php

namespace App\Service\Index;

use App\Model\HostBlacklist;
use App\Model\User;
use App\Model\UserCancelLog;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 首页悬浮按钮展示（一键聊天和新首福利）
 */
class PopDetailService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $profile = UserProfile::getProfile($userId);
        //马甲包暂时不显示
        $show = $this->appId == 1 ? 1 : 0;
        if ($profile->gender == 1) $ret = ['new_gift' => ['show' => $show]];
        else {
            $checkHost = UserProfile::checkRoleUser($profile->role);
            //声优认证引导
            $ret['apply_host'] = [
                'show' => $checkHost ? 1 : 0,
                'text' => '实名认证后，即可开启赚钱',
                'title' => '开启赚钱',
                'button_txt' => '去实名认证'
            ];
            //主播显示天天福利
            if (User::checkValidVersion($this->curVersion, $this->appId, [1 => '1.0.0', 2 => '1.0.0'])) {
                $ret['new_gift'] = ['show' => 0];
            } else {
                $showDailyFree = UserProfile::checkRoleHost($profile->role) && !HostBlacklist::checkBlack($userId);
                $ret['new_gift'] = ['show' => $show && $showDailyFree ? 1 : 0];
            }
            log_user_result($userId, $ret);
        }
        //注销申请提醒
        $this->packCancelTip($ret, $userId);
        return $ret;
    }

    /**
     * 注销申请
     */
    function packCancelTip(&$ret = [], $userId = 0)
    {
        if ($this->curVersion < '1.0.0') return [];
        $result = UserCancelLog::checkStatus($userId);
        if ($result['status'] == -1) {
            $ret['cancel_info'] = '是否取消注销？';
        } else {
            $ret['cancel_info'] = '';
        }
    }
}
